<?php

namespace app\admin\service;

use app\admin\dao\MemberDao;
use app\admin\model\UM as UM;
use app\common\model\Member;
use app\index\service\MemberTokenService;

/**
 * Class MemberWeixinService
 * @package app\admin\service
 */
class MemberWeixinService
{
    // dao
    private MemberDao $memberDao;

    public function __construct(MemberDao $memberDao)
    {
        $this->memberDao = $memberDao;
    }

    /**
     * 删除
     * @param UM $user
     * @param int $id
     */
    public function rm(UM $user, int $id): void
    {
        //这里如果要修改查询，建议把查询就放到这里
        $record = Member::field(true)->where('id', $id)->find();

        if (is_null($record)) {
            return;
        }

        $record->unionid = '';
        $record->openidWeiXin = '';
        $record->openidWechat = '';
        $record->openidWechatOpen = '';
        $record->followedWechat = '0';
        $record->save();

        // 退出登录
        $this->getMemberTokenService()->delete($record->id);
    }

    private function getMemberTokenService(): MemberTokenService
    {
        return app(MemberTokenService::class);
    }
}
